﻿namespace EyeOpen.Validation.Test
{
    using System;
    using EyeOpen.Validation.Mapping;

    /// <summary>
    /// Allows to validate a <see cref="FooEntity"/>.
    /// </summary>
    public class FooValidator : EntityValidator<FooEntity>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FooValidator"/> class.
        /// </summary>
        public FooValidator()
            : base(new FooValidationMapping())
        {
        }

        /// <summary>
        /// Validates the entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        protected override void ValidateEntity(FooEntity entity)
        {
            if (string.IsNullOrEmpty(entity.Name) && string.IsNullOrEmpty(entity.Lastname))
            {
                return;
            }

            if (entity.Name != null)
            {
                if (entity.Name.Equals(entity.Lastname, StringComparison.InvariantCultureIgnoreCase))
                {
                    var validationResult = new ValidationResult();
                    validationResult.ValidationMessages.Add("Name must be different from LastName");
                    AddValidationResult(validationResult);
                }
            }
        }
    }
}